<?php
declare(strict_types=1);

namespace Modules\Production\Http\Controllers;

use Catch\Base\CatchController as Controller;
use Modules\Production\Models\DassemblyOrderProduct;
use Illuminate\Http\Request;use Modules\Production\Repository\DassemblyOrderProductRepository;


class DassemblyOrderProductController extends Controller
{
    public function __construct(
        protected readonly DassemblyOrderProduct $model
    ){}

    /**
     * @param Request $request
     * @return mixed
     */
    public function index(): mixed
    {
        return $this->model->getList();
    }

    /**
     * @param Request $request
     * @return mixed
     */
    public function store(Request $request)
    {
        return $this->model->storeBy($request->all());
    }

    /**
     * @param $id
     * @return mixed
     */
    public function show($id)
    {
        return $this->model->firstBy($id);
    }

    /**
     * @param Request $request
     * @param $id
     * @return mixed
     */
    public function update($id, Request $request)
    {
        return $this->model->updateBy($id, $request->all());
    }

    /**
     * @param $id
     * @return mixed
     */
    public function destroy($id)
    {
        return $this->model->deleteBy($id);
    }

    /**
     * 拆卸成品出库扫描
     * @param $productId
     * @param Request $request
     * @return array
     * @throws Exception
     */
    public function DassemblyOutScan($productId,Request $request){
        return DassemblyOrderProductRepository::DassemblyOutScan($productId,$request->get('lotnum'));
    }

    /**
     * 拆卸成品出库提交
     * @param $productId
     * @param Request $request
     * @return bool
     * @throws Exception
     */
    public function DassemblyOut($productId,Request $request){
        return DassemblyOrderProductRepository::DassemblyOut($productId,$request->post());
    }
}
